package com.konsung.ksdc.manager.shop;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * 轮播图adapter
 * Created by Administrator on 2016/4/25 0025.
 */
public class LoopAdapter extends PagerAdapter {
    public List<View> picData;

    /**
     * 构造方法
     * @param context 上下文
     * @param viewList page集合
     */
    public LoopAdapter(Context context, List<View> viewList) {
        picData = viewList;
    }

    @Override
    public int getCount() {
        return picData.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {

        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        try {
            container.addView(picData.get(position), 0);
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        return picData.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        try {
            container.removeView(picData.get(position));
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        }
    }
}